﻿using System;
using System.Collections.Generic;
using System.Linq;

namespace EdlinSoftware.RegexTester.Code
{
    internal class FileShortcutsProvider
    {
        #region Fields

        private const string StorageFileName = "FileShortcuts.dat";

        private readonly TextLinesStorage _storage = new TextLinesStorage();

        private static readonly HashSet<string> _fileShortcuts = new HashSet<string>(StringComparer.CurrentCultureIgnoreCase);

        #endregion

        #region Methods

        public void AddFileShortcut(string fileName)
        {
            if (!string.IsNullOrEmpty(fileName))
            {
                _fileShortcuts.Add(fileName);
            }
        }

        public void RemoveFileShortcuts(IEnumerable<string> fileNames)
        {
            _fileShortcuts.RemoveWhere(f => fileNames.Contains(f));
        }

        public string[] GetAllFileShortcuts()
        {
            return _fileShortcuts.ToArray();
        }

        public void LoadShortcuts()
        {
            _fileShortcuts.Clear();

            foreach (string shortcut in _storage.GetLinesFromFile(StorageFileName))
            {
                _fileShortcuts.Add(shortcut);
            }
        }

        public void SaveShortcuts()
        {
            _storage.SaveLinesToFile(StorageFileName, _fileShortcuts);
        }

        #endregion
    }
}
